package tcpVerbindung;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class ByteWeise {

	/**
	 * 
	 * @param socket
	 * @param datenWort
	 * @param datenParameter
	 * @throws IOException
	 */
	public static void sendenListe(Socket socket, short[] datenWort, int[] datenParameter) throws IOException {
		DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());

		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < datenWort.length; j++) {
				outToServer.writeShort(datenWort[j]);
			}

			for (int j = 0; j < datenParameter.length; j++) {
				outToServer.writeInt(datenParameter[j]);
			}

			outToServer.flush();
			try {
				Thread.sleep(10L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 
	 * @param socket
	 * @param datenByte
	 * @param datenInt
	 * @param datenFloat
	 * @throws IOException
	 */
	public static void sendenListe(Socket socket, byte[] datenByte, int[] datenInt, float[] datenFloat) throws IOException {
		DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());

		for (int j = 0; j < datenByte.length; j++) {
			outToServer.writeByte(datenByte[j]);
		}

		for (int j = 0; j < datenInt.length; j++) {
			outToServer.writeInt(datenInt[j]);
		}

		for (int j = 0; j < datenFloat.length; j++) {
			outToServer.writeFloat(datenFloat[j]);
		}

		outToServer.flush();
	}

	/**
	 * 
	 * @param dataInputStream
	 * @param laenge
	 * @return
	 * @throws IOException
	 */
	public static short[] getEmpfangenShort(DataInputStream dataInputStream, int laenge) throws IOException {

		short[] daten = new short[laenge];

		for (int i = 0; i < laenge; i++) {
			daten[i] = dataInputStream.readShort();
		}

		return daten;
	}

	/**
	 * 
	 * @param dataInputStream
	 * @param laenge
	 * @return
	 * @throws IOException
	 */
	public static int[] getEmpfangenInt(DataInputStream dataInputStream, int laenge) throws IOException {
		int[] daten = new int[laenge];

		for (int i = 0; i < laenge; i++) {
			daten[i] = dataInputStream.readInt();
		}

		return daten;
	}

	/**
	 * 
	 * @param dataInputStream
	 * @param laenge
	 * @return
	 * @throws IOException
	 */
	public static float[] getEmpfangenFloat(DataInputStream dataInputStream, int laenge) throws IOException {
		float[] daten = new float[laenge];

		for (int i = 0; i < laenge; i++) {
			daten[i] = dataInputStream.readFloat();
		}

		return daten;
	}

	/**
	 * 
	 * @param dataInputStream
	 * @param laenge
	 * @return
	 * @throws IOException
	 */
	public static byte[] getEmpfangenBool(DataInputStream dataInputStream, int laenge) throws IOException {
		byte[] daten = new byte[laenge];

		for (int i = 0; i < laenge; i++) {
			daten[i] = dataInputStream.readByte();
		}

		return daten;
	}
}